package cn.glutnn.oss.controller;

import cn.glutnn.oss.service.FileService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * Author:   msh
 * Date:     2024/12/4 下午9:46
 * Description:
 */
@RestController
@RefreshScope
public class FileController {

    @Resource
    private FileService fileService;

//    @NacosValue(value = "${storage.service.type}",autoRefreshed = true )
    @Value("${storage.service.type}")
    private String storageType;

    @RequestMapping("/test")
    public String test() throws Exception {
        return fileService.listBuckets().toString();
    }

    @RequestMapping("/testNacos")
    @RefreshScope
    public String testNacos(){
        System.out.println("storageType: " + storageType);
        return storageType;
    }

    // 上传文件
    @RequestMapping("/upload")
    public String upload(MultipartFile file, String bucket, String objectName) throws Exception {
        return fileService.upload(file,bucket, objectName);
    }
}
